package com.lagou.dao;

import com.lagou.entity.Employee;
import com.lagou.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author wsl
 * @Date 2021/8/26 17:24
 * @Project_Name mysql
 */
public class EmployeeDao {

    /**
     * 编写一个测试类，在该测试类中使用PrepareStatement
     * 根据name和gender进行数据查询，并将结果打印在控制台。
     */

    public ResultSet findEmployee(String name,String gender) throws SQLException {

        //1.获取连接
        Connection con = DBUtils.getConnection();

        //2.获取PrepareStatement对象
        String sql = "select * from employee where name = ? and gender = ?";
        PreparedStatement ps = con.prepareStatement(sql);

        //3.设置占位符参数
        ps.setString(1,name);
        ps.setString(2,gender);

        //4.执行查询
        ResultSet resultSet = ps.executeQuery();

        return resultSet;
    }
}
